package com.ming.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.domain.Area;
import com.ming.sevice.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:何元才
 * @Desc:
 * @data:2021-04-02 17:22
 */
@RestController
@RequestMapping("/admin/area")
@Api(tags = "区域管理接口")
public class AreaController {

    @Autowired
    private AreaService areaService;


    @GetMapping("list")
    @ApiOperation("全查询区域")
    @PreAuthorize("hasAuthority('shop:area:list')")
    public ResponseEntity<List<Area>> findAreaPage(){
        List<Area> areas = areaService.list();
        return ResponseEntity.ok(areas);
    }



    @GetMapping("listByPid")
    @ApiOperation("根据父id查询子区域")
    public ResponseEntity<List<Area>> listByPid(Long pid) {
        List<Area> areas = areaService.listByPid(pid);
        return ResponseEntity.ok(areas);
    }
}
